﻿using BCC.Model.commodity;
using BCC.ViewModel.commodity;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using static BCC.ViewModel.commodity.CommodityMainVM;

namespace BCC.Commodity
{
    /// <summary>
    /// CommodityMain.xaml 的交互逻辑
    /// </summary>
    public partial class CommodityMain : Window
    {
        public ObservableCollection<SCommodity> ShoppingCart=new ObservableCollection<SCommodity>();
        public CommodityMain()
        {
            InitializeComponent();
            CommodityMainVM commodityMain = new CommodityMainVM();
            // 初始化商品列表和购物车
            //commodityMain.Products = new ObservableCollection<SCommodity>();

            commodityMain.ShoppingCart = ShoppingCart;

            DataContext = commodityMain;
        }


        /// <summary>
        /// 添加到购物车
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddToCart_Click(object sender, RoutedEventArgs e)
        {
            var button = (Image)sender;
            var product = (SCommodity)button.Tag;

            ShoppingCart.Add(product);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RemoveFromCart_Click(object sender, RoutedEventArgs e)
        {
            var button = (Button)sender;
            var product = (SCommodity)button.Tag;

            ShoppingCart.Remove(product);

            //购买
        }

    }
}
